package com.situ.controller;




import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.situ.dao.IvIninvoiceDao;
import com.situ.dao.IvInvoiceDao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.situ.service.IvIninvoiceService;
import com.situ.entity.IvIninvoice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
 * IvIninvoice的路由接口服务
 *
 * @author 胡文
 */
@Controller
public class IvIninvoiceController {



	/** IvIninvoiceService服务 */
	@Autowired
	private IvIninvoiceService ivIninvoiceService;
	//查询员工的方法
	@RequestMapping("inv_invoiceReportEmp.html")
	public String queryEmp(Map map,
						   @RequestParam(defaultValue ="1",required = false) int startPage,
						   @RequestParam(defaultValue = "5",required = false) int PageSize){
		PageHelper.startPage(startPage, PageSize);

		List<Map> elist=ivIninvoiceService.queryemp();

		PageInfo pageInfo = new PageInfo<Map>(elist,5);

		map.put("pageInfo", pageInfo);
		map.put("startPage", startPage);
		map.put("PageSize", PageSize);
		map.put("elist", elist);
		return "page/inv_invoiceReportEmp.html";
	}
	/**
	 * 查询所有IvIninvoice数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryIvIninvoice", produces = {"application/json;charset=UTF-8"})
	public String find1(IvIninvoice value,Map map) {
		 List<IvIninvoice> list= ivIninvoiceService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	
	
  


    @Autowired(required = false)
    private IvIninvoiceDao ivIninvoiceDao;
    private IvIninvoice StartNo;
    private IvIninvoice EndNo;



    /**
     * 通过id查询IvIninvoice数据的方法
     *
     * @return
     */
    @RequestMapping(value = "queryIvIninvoiceById/{id}", produces = {"application/json;charset=UTF-8"})
    public String findOne(@PathVariable(name = "id") Object id, Map map) {
        IvIninvoice obj = ivIninvoiceService.findOne(id);
        map.put("IvIninvoice", obj);

        return "页面名称自己改";
    }

    /**
     * 插入IvIninvoice
     * 属性不为空的数据方法
     *
     * @return
     */
    @RequestMapping("addview")
    public ModelAndView addview(Model modle) {
        modle.addAttribute("date", new Date());
        return new ModelAndView("inv_invoiceIn.html");
    }

    @RequestMapping(value = "/saveIvIninvoice", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public void save(IvIninvoice value, HttpServletRequest request, HttpServletResponse response) throws IOException {
        String startno = request.getParameter("StartNo");
        String endno = request.getParameter("EndNo");
        List<IvIninvoice> w = ivIninvoiceDao.inputchack(startno, endno);
        System.out.println(startno);
        System.out.println(endno);
        PrintWriter out = response.getWriter();
        if (w.isEmpty()) {
            value.setInDate(new Date());
            value.setStartNo(request.getParameter("StartNo").toString());
            value.setEndNo(request.getParameter("EndNo").toString());
            value.setInvoiceType(Integer.parseInt(request.getParameter("InvoiceType")));
            value.setCounts(Integer.parseInt(request.getParameter("Counts")));
            int i = ivIninvoiceDao.insertIvIninvoice(value);

            out.write("true");
        } else {
            System.out.println("false");
        }


    }


}
